﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_client_contact_details
{
    public DAL_tbl_client_contact_details()
    {

    }



    public List<tbl_client_contact_details> select(int CONTACT_ID)
    {
        List<tbl_client_contact_details> list = new List<tbl_client_contact_details>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select CONTACT_ID,USER_CODE,CONTACT_NAME,PRIMARY_CONTACT_NUMBER,SECONDARY_CONTACT_NUMBER,DEPARTMENT_ID,DESIGNATION_ID,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_client_contact_details where CONTACT_ID=@CONTACT_ID";
        cmd.Parameters.AddWithValue("@CONTACT_ID", CONTACT_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_client_contact_details()
            {
                CONTACT_ID = Convert.ToInt32(dr["CONTACT_ID"]),
                USER_CODE = dr["USER_CODE"].ToString(),
                CONTACT_NAME = dr["CONTACT_NAME"].ToString(),
                PRIMARY_CONTACT_NUMBER = dr["PRIMARY_CONTACT_NUMBER"].ToString(),
                SECONDARY_CONTACT_NUMBER = dr["SECONDARY_CONTACT_NUMBER"].ToString(),
                DEPARTMENT_ID = dr["DEPARTMENT_ID"].ToString(),
                DESIGNATION_ID = dr["DESIGNATION_ID"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_client_contact_details> selectAll()
    {
        List<tbl_client_contact_details> list = new List<tbl_client_contact_details>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select CONTACT_ID,USER_CODE,CONTACT_NAME,PRIMARY_CONTACT_NUMBER,SECONDARY_CONTACT_NUMBER,DEPARTMENT_ID,DESIGNATION_ID,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_client_contact_details Order By CONTACT_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_client_contact_details()
            {
                CONTACT_ID = Convert.ToInt32(dr["CONTACT_ID"]),
                USER_CODE = dr["USER_CODE"].ToString(),
                CONTACT_NAME = dr["CONTACT_NAME"].ToString(),
                PRIMARY_CONTACT_NUMBER = dr["PRIMARY_CONTACT_NUMBER"].ToString(),
                SECONDARY_CONTACT_NUMBER = dr["SECONDARY_CONTACT_NUMBER"].ToString(),
                DEPARTMENT_ID = dr["DEPARTMENT_ID"].ToString(),
                DESIGNATION_ID = dr["DESIGNATION_ID"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String USER_CODE, String CONTACT_NAME, String PRIMARY_CONTACT_NUMBER, String SECONDARY_CONTACT_NUMBER, String DEPARTMENT_ID, String DESIGNATION_ID, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_client_contact_details(USER_CODE, CONTACT_NAME, PRIMARY_CONTACT_NUMBER, SECONDARY_CONTACT_NUMBER, DEPARTMENT_ID, DESIGNATION_ID, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@USER_CODE, @CONTACT_NAME, @PRIMARY_CONTACT_NUMBER, @SECONDARY_CONTACT_NUMBER, @DEPARTMENT_ID, @DESIGNATION_ID, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@USER_CODE", USER_CODE);
        cmd.Parameters.AddWithValue("@CONTACT_NAME", CONTACT_NAME);
        cmd.Parameters.AddWithValue("@PRIMARY_CONTACT_NUMBER", PRIMARY_CONTACT_NUMBER);
        cmd.Parameters.AddWithValue("@SECONDARY_CONTACT_NUMBER", SECONDARY_CONTACT_NUMBER);
        cmd.Parameters.AddWithValue("@DEPARTMENT_ID", DEPARTMENT_ID);
        cmd.Parameters.AddWithValue("@DESIGNATION_ID", DESIGNATION_ID);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int CONTACT_ID, String USER_CODE, String CONTACT_NAME, String PRIMARY_CONTACT_NUMBER, String SECONDARY_CONTACT_NUMBER, String DEPARTMENT_ID, String DESIGNATION_ID, bool IS_ACTIVE, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_client_contact_details SET USER_CODE=@USER_CODE, CONTACT_NAME=@CONTACT_NAME, PRIMARY_CONTACT_NUMBER=@PRIMARY_CONTACT_NUMBER, SECONDARY_CONTACT_NUMBER=@SECONDARY_CONTACT_NUMBER, DEPARTMENT_ID=@DEPARTMENT_ID, DESIGNATION_ID=@DESIGNATION_ID, IS_ACTIVE=@IS_ACTIVE, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE CONTACT_ID=@CONTACT_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@CONTACT_ID", CONTACT_ID);
        cmd.Parameters.AddWithValue("@USER_CODE", USER_CODE);
        cmd.Parameters.AddWithValue("@CONTACT_NAME", CONTACT_NAME);
        cmd.Parameters.AddWithValue("@PRIMARY_CONTACT_NUMBER", PRIMARY_CONTACT_NUMBER);
        cmd.Parameters.AddWithValue("@SECONDARY_CONTACT_NUMBER", SECONDARY_CONTACT_NUMBER);
        cmd.Parameters.AddWithValue("@DEPARTMENT_ID", DEPARTMENT_ID);
        cmd.Parameters.AddWithValue("@DESIGNATION_ID", DESIGNATION_ID);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int CONTACT_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_client_contact_details WHERE CONTACT_ID=@CONTACT_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@CONTACT_ID", CONTACT_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}